package com.whpost.api.controller.wx;

import com.alibaba.fastjson.JSON;
import com.whpost.api.utils.ApiUtils;
import com.whpost.service.entity.tools.ResultInfo;
import com.whpost.service.wx.service.WechatJsService;
import jakarta.annotation.Resource;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.Base64;
import java.util.Map;

@RestController
public class WxJsApiController {

    @Resource
    private WechatJsService wechatJsService;

    /**
     * 处理前端wxJs接口请求，生成JSSDK签名
     * 前端传递加密后的参数，后端解密处理后返回加密的签名数据
     */
    @PostMapping("/wxJs")
    public ResultInfo getWxJsConfig(@RequestBody Map<String, Object> map) {
        String loginId = ApiUtils.getLoginId();
        return wechatJsService.getWxJsConfig(loginId,map);
    }


}